package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    void insert(Orders orders);

    @Select("SELECT * FROM orders WHERE number =#{outTradeNo} AND user_id = #{userId}" )
    Orders getByNumber(String outTradeNo,Long userId);

    void update(Orders orders);

    Page<Orders> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("SELECT * FROM orders WHERE id = #{id}")
    Orders getById(Long id);

    Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("SELECT COUNT(*) FROM orders WHERE status = #{status}")
    Integer count(Orders orders);

    @Select("SELECT * FROM orders WHERE status = #{status} AND order_time < #{time}")
    List<Orders> selectTimeOutOrder(Integer status, LocalDateTime time);

    // 统计订单金额
    Double turnoverStatistics(Map map);

    // 统计订单数量
    Integer countOrders(Map map);

    List<GoodsSalesDTO> top10(LocalDateTime beginTime, LocalDateTime endTime);
}
